Laravel / Model / Separate db for Read write
Separate db for read wtire
-
STEPS
1. .env
DB_CONNECTION=mysql #DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel_db DB_USERNAME=larave_user DB_PASSWORD=Laravel_Pa55word_here! 2. config/database.php
'mysql' => [ 'read' => [ 'host' => [ '157.230.25.155', ], ], 'write' => [ 'host' => [ '139.59.155.119', ], ], 3. Controller
DB::connection('mysql::write')->select(...); Or User::on('mysql::write')->find(1); User::on('mysql::read')->get(); User::on('mysql::read')->all(); or User::on('mysql::read')->find(1);